"""
import pymysql
class DB:
    def __init__(self,host,user,password,database,cursorclass):

        :param host: 就是阿里云服务器的ip地址
        :param user: 数据库的账号名  一般都是root
        :param password: 数据库密码
        :param database: 数据库的名字
        :param cursorclass:  返回的格式是字典格式，有key和value

        self.host = host
        self.user = user
        self.password = password
        self.database = database
        self.cursorclass = cursorclass
    def connect(self):
        # 创建数据库对象
        self.db = pymysql.connect(host = self.host,user = self.user,password = self.password,database=self.database,cursorclass=self.cursorclass)
        # 创建游标对象
        self.cursor = self.db.cursor()
    def close(self):
        self.cursor.close() # 先关闭游标
        self.db.close() # 再关闭数据库对象
    def select_all(self,sql): # 查询全部的数据
        result = 0
        try:
            self.connect() # 先连接
            self.cursor.execute(sql)
            result = self.cursor.fetchall() #
            self.close()
            return result
        except Exception as ec:
            self.db.rollback() #如果sql执行错误，先回滚
            print("数据库sql有误%s"%ec)
            return result
    def select_one(self,sql):
        result = 0
        try:
            self.connect()  # 先连接
            self.cursor.execute(sql)
            result = self.cursor.fetchone()
            self.close()
            return result
        except Exception as ec:
            self.db.rollback()  # 如果sql执行错误，先回滚
            print("数据库sql有误%s" % ec)
            return result
    def __edit(self,sql): #主程序
        self.connect()
        try:
            self.cursor.execute(sql)
            self.db.commit()
            self.close()
            result = True
            return result
        except Exception as ec:
            self.db.rollback() # 如果sql执行错误，回滚
            print("数据库sql有误%s"%ec)
            result = False
            return result
    def insert(self,sql):
        return self.__edit(sql)

    def update(self,sql):
        return self.__edit(sql)
    def delete(self,sql):
        return self.__edit(sql)
# 通过DB类，实例化db1对象
db1 = DB(host = "112.124.71.77",user = 'root',password='123456',database='guan',cursorclass=pymysql.cursors.DictCursor)
a = 'insert into student(name,classid) values("关博文",1703)'
db1.insert(a)
print(db1.select_all('select * from student'))
# print()
# print(db1.select_all('select * from student'))
"""
from selenium import  webdriver
from selenium.webdriver.common.by import By

option = webdriver.ChromeOptions() # todo：chrome浏览器配置项
option.add_experimental_option("detach", True)# todo：浏览器不会自动关闭
driver = webdriver.Chrome(options=option)
driver.get('https://www.baidu.com/')
driver.find_element(By.ID,'kw').send_keys('知网')

"""
import time,os
from selenium import webdriver
from selenium.webdriver.common.by import By # todo:引入By方法，做selenium定位
option = webdriver.ChromeOptions() # todo：chrome浏览器配置项
option.add_experimental_option("detach", True)# todo：浏览器不会自动关闭
bro = webdriver.Chrome(options=option) # todo：实例化driver
# executable_path：指定driver的路径
bro.get("https://www.baidu.com/") # todo：打开一个浏览器页面
bro.maximize_window() # todo：浏览器放大
#bro.minimize_window() # todo:浏览器缩小
time.sleep(2) # todo：强制等待2s
bro.find_element(By.ID, "kw").send_keys("selenium")

time.sleep(3)
bro.find_element(By.ID, "su").click()
time.sleep(3)
"""